<?php
	//调用配置文件SQLHelper.class.php
	require_once 'SQLHelper.class.php';
	
	$sqlHelper =  new SQLHelper();
	
	//如果数据库没有blog,admin,catalogs三个表，则创建
	$sql1 = "create table  if not exists blog(
id int primary key auto_increment,
title varchar(64) not null,
content text not null,
cid int(10),
time timestamp default now()
)default charset=utf8";
	$sql2 = "create table if not exists admin(
id int primary key auto_increment,
name varchar(32) not null,
password varchar(64) not null
)default charset=utf8";
	$sql3 = "create table if not exists catalogs(
cid int primary key auto_increment,
catalog varchar(32) not null
)default charset=utf8";
	$sqlHelper->execute_ddl($sql1) ;
	$sqlHelper->execute_ddl($sql2) ;
	$sqlHelper->execute_ddl($sql3) ;
	
	
	//如果有建表，查询admin表中第一行是否有一行记录,如果没有就输入测试数据
	$res = $sqlHelper->execute_dql("select * from admin limit 0,1") ;
	if(empty($res)){
		$sql1="insert into blog(title, content,cid) value('Hello World','你好，世界',1)";
		$sql2="insert into admin(name, password) value('simbs',md5('simbs'))";
		$sql3="insert into catalogs(catalog) value('linux')";
		$sql4="insert into catalogs(catalog) value('内核')";
		$sql5="insert into catalogs(catalog) value('Gnome')";
		$sql6="insert into catalogs(catalog) value('Qt')";
			
		$sqlHelper->execute_dml($sql1);
		$sqlHelper->execute_dml($sql2);
		$sqlHelper->execute_dml($sql3);
		$sqlHelper->execute_dml($sql4);
		$sqlHelper->execute_dml($sql5);
		$sqlHelper->execute_dml($sql6);
		
	}
	//不必关闭资源，资源在SQLHelper.class.php中关闭好了，这里只需关闭数据库
	$sqlHelper->close_connect();

	header('Location: blogManage.php');
?>
